#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>

void panic(char *message) {
    perror(message);
    exit(1);
}

int main(int argc, char *argv[]) {
    DIR *dirp;
    struct dirent *direntp;
    char *path;

    if(argc == 1) path = ".";
    else path = argv[1];

    if ((dirp = opendir(path)) == NULL)
        panic("opendir");

    while ((direntp = readdir(dirp)) != NULL) {
        char *name = direntp->d_name;
        if (!strcmp(name, ".") || !strcmp(name, "..")) continue;
        printf("%s\n", name);
    }

    closedir(dirp);
    return 0;
}
